package com.lxl.bt.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.lxl.bt.R;
import com.lxl.bt.activity.BaseFragment;
import com.lxl.bt.util.ACache;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Create by lvxinlong
 * on btc
 * on 2021年3月6日10:00:20
 **/
public class ProductDetailHintFragment extends BaseFragment {


    @BindView(R.id.tvContent)
    WebView tvContent;
    private Unbinder unbinder;
    ACache aCache;
    int type = 0;

    public static ProductDetailHintFragment newInstance(int type, String url) {
        Bundle bundle = new Bundle();
        ProductDetailHintFragment fragment = new ProductDetailHintFragment();
        bundle.putInt("type", type);
        bundle.putString("url", url);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            type = getArguments().getInt("type");
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_producthint, container, false);
//        ((BaseActivity) getActivity()).setStatusBarFullTransparent();

        //返回一个Unbinder值（进行解绑），注意这里的this不能使用getActivity()
        unbinder = ButterKnife.bind(this, view);
//        EventBus.getDefault().register(this);
        aCache = ACache.get(getActivity());
        Log.i("loadUrl",getArguments().getString("url"));
        tvContent.loadUrl(getArguments().getString("url"));
        tvContent.setWebViewClient(new WebViewClient());
        tvContent.setOnTouchListener((v, event) -> {
            if (!(getActivity() instanceof IOnWebViewTouch)) {
                return false;
            }
            if (event.getActionMasked() == MotionEvent.ACTION_UP) {
                ((IOnWebViewTouch) getActivity()).onWebViewTouch(false);
            } else {
                ((IOnWebViewTouch) getActivity()).onWebViewTouch(true);
            }
            return false;
        });
        return view;
    }


    @Override
    public void onResume() {
        super.onResume();
    }


    @Override
    public void getData() {
        notifyList();
    }

    public void notifyList() {
        List<String> ss = new ArrayList<>();
//        JsonObject jsonObject = new JsonObject();
//        jsonObject.addProperty("pageNo", pageNo);
//        jsonObject.addProperty("pageSize", 20);
//        RetrofitUtil.getInstance().create(NetApi.class, 0)
//                .notifyList(Prefs.getStringValue(Constant.JSESSIONID), jsonObject).enqueue(new NetCallback<Result<NotifyBody>>() {
//            @Override
//            public void onSuccess(Result<NotifyBody> result) {
//                if (result.isSuccess()) {
//                    refreshLayout.finishRefresh();
//                    refreshLayout.finishLoadMore();
//                    if (pageNo == 1)
//                        sysAdapter.setNewData(result.getData().getOaNotifyList());
//                    else
//                        sysAdapter.addData(result.getData().getOaNotifyList());
//
//                    sysAdapter.setEnableLoadMore(result.getData().totalPage > pageNo ? true : false);
//                    pageNo++;
//                }
//            }
//
//            @Override
//            public void netLogin() {
//
//            }
//
//            @Override
//            public void onError(String errorStr) {
//                super.onError(errorStr);
//                Log.w("lxl", errorStr);
//
//            }
//
//        });
    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
    }


//    @Subscribe
//    public void onEventMainThread(EventTagBean event) {
//    }

    /**
     * onDestroyView中进行解绑操作
     */
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

    }

}
